package com.dailyblue.java.design.观察者模式;

import java.util.Stack;

public class WelfareLottery extends Subject {

    private Integer num;
    private Stack<Observer> stack = new Stack<>();

    @Override
    public void registerObserver(Observer observer) {
        stack.push(observer);
    }

    @Override
    public void removeObserver(Observer observer) {
        stack.remove(observer);
    }

    @Override
    public void notifyObserver() {
        num = (int) (Math.random() * 33 + 1);
        stack.forEach(e -> {
            e.update("中奖号码是：" + num);
        });
    }
}
